package liangtWorkSpace.celaderTest;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class CelanderTest {

    public static void main(String[] args) {
        String yearMonthStr = format(new Date(), "yyyyMM");
        System.out.println(yearMonthStr);
        Integer yearMonth = Integer.valueOf(yearMonthStr);
        System.out.println(yearMonth);
        Integer yearMonthI = yearMonth % 100;
        System.out.println(yearMonthI);
        if (yearMonthI >= 3) {
            yearMonthStr = String.valueOf(yearMonth - 2);
        } else {
            yearMonthStr = String.valueOf(yearMonth - 90);
        }
        System.out.println(yearMonthStr);
        System.out.println("----------------------------");
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MONTH,2);
        System.out.println(calendar.get(Calendar.YEAR));
        System.out.println(calendar.get(Calendar.MARCH));
        System.out.println(calendar.get(Calendar.DAY_OF_YEAR));
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));

        Calendar c = new GregorianCalendar();
        System.out.println(c.get(Calendar.YEAR));
        System.out.println(c.get(Calendar.MARCH));
        System.out.println(c.get(Calendar.DAY_OF_YEAR));
        System.out.println(c.get(Calendar.DAY_OF_MONTH));
    }

    public static String format(Date p_date, String p_format) {

        if (p_date == null) {
            return "";
        }
        return new SimpleDateFormat(p_format).format(p_date);
    }
}
